using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;

namespace Terra.Data.Entities.Identity;

/// <summary>
/// 密码重置令牌实体
/// </summary>
[Table("PasswordResetTokens")]
[Comment("密码重置令牌表")]
[Index(nameof(Token), Name = "IX_PasswordResetTokens_Token", IsUnique = true)]
[Index(nameof(UserId), Name = "IX_PasswordResetTokens_UserId")]
[Index(nameof(CreatedTime), Name = "IX_PasswordResetTokens_CreatedTime")]
public class PasswordResetToken : EntityBase<Guid>
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Comment("用户ID")]
    public Guid UserId { get; set; }

    /// <summary>
    /// 令牌
    /// </summary>
    [Required]
    [MaxLength(128)]
    [Comment("重置令牌，唯一值")]
    public string Token { get; set; }

    /// <summary>
    /// 重置类型
    /// </summary>
    [Comment("重置类型：1-邮件重置，2-短信重置，3-管理员重置")]
    public int ResetType { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Comment("创建时间")]
    public DateTime CreatedTime { get; set; }

    /// <summary>
    /// 过期时间
    /// </summary>
    [Comment("过期时间")]
    public DateTime ExpiresTime { get; set; }

    /// <summary>
    /// 使用时间
    /// </summary>
    [Comment("使用时间")]
    public DateTime? UsedTime { get; set; }

    /// <summary>
    /// 是否已使用
    /// </summary>
    [Comment("是否已使用：true-已使用，false-未使用")]
    public bool IsUsed { get; set; }

    /// <summary>
    /// 导航属性 - 用户
    /// </summary>
    [ForeignKey(nameof(UserId))]
    public virtual User User { get; set; }
}